#include<bits/stdc++.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=1e9+7;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}

signed main(){
	freopen("alien.in","r",stdin);
	freopen("alien.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	int T=read();
	while(T--){
		int a=read(),b=read(),c=read();
		if(max(a,max(b,c))<=11){
			int ans=0;
			For(i,1,a){
				For(j,1,b){
					For(t,1,c){
						int x=1;
						For(k,1,i) x*=j;
						int y=1;
						For(k,1,t) y*=i;
						ans+=(x==y);
					}
				}
			}
			printf("%lld\n",ans);
			continue;
		}
		int ans=c;
		For(i,2,a){
			For(j,2,b){
				int g=__gcd(i,j);
				int x=i/g,y=j/g;
				if(x!=1&&y!=1) continue;
				if(i<=j){
					int p=0,s=1;
					while(s<j){
						s=s*i;
						p++;
					}
					if(s!=j) continue;
					if(p*i>c) continue;
					ans++;
				}
				else{
					int p=0,s=1;
					while(s<i){
						s=s*j;
						p++;
					}
					if(s!=i) continue;
					if(i/p>c||i%p!=0) continue;
					ans++;
				}
			}
		}
		ans%=Mod;
		printf("%lld\n",ans);
	}
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

